package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.JkEducation;
import com.ruoyi.service.IJkEducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宣教管理Controller
 *
 * @author ruoyi
 * @date 2023-09-08
 */
@RestController
@RequestMapping("/push/education")
public class JkEducationController extends BaseController
{
    @Autowired
    private IJkEducationService jkEducationService;

    /**
     * 查询宣教管理列表
     */
    @PreAuthorize("@ss.hasPermi('push:education:list')")
    @GetMapping("/list")
    public TableDataInfo list(JkEducation jkEducation)
    {
        startPage();
        List<JkEducation> list = jkEducationService.selectJkEducationList(jkEducation);
        return getDataTable(list);
    }

    /**
     * 导出宣教管理列表
     */
    @PreAuthorize("@ss.hasPermi('push:education:export')")
    @Log(title = "宣教管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkEducation jkEducation)
    {
        List<JkEducation> list = jkEducationService.selectJkEducationList(jkEducation);
        ExcelUtil<JkEducation> util = new ExcelUtil<JkEducation>(JkEducation.class);
        util.exportExcel(response, list, "宣教管理数据");
    }

    /**
     * 获取宣教管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('push:education:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jkEducationService.selectJkEducationById(id));
    }

    /**
     * 新增宣教管理
     */
    @PreAuthorize("@ss.hasPermi('push:education:add')")
    @Log(title = "宣教管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JkEducation jkEducation)
    {
        return toAjax(jkEducationService.insertJkEducation(jkEducation));
    }

    /**
     * 修改宣教管理
     */
    @PreAuthorize("@ss.hasPermi('push:education:edit')")
    @Log(title = "宣教管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JkEducation jkEducation)
    {
        return toAjax(jkEducationService.updateJkEducation(jkEducation));
    }

    /**
     * 删除宣教管理
     */
    @PreAuthorize("@ss.hasPermi('push:education:remove')")
    @Log(title = "宣教管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jkEducationService.deleteJkEducationByIds(ids));
    }
}
